package com.hosever.action;

import java.text.DecimalFormat;
import java.util.Random;

/**
 * 陈晓忻的计算器
 * @author Sever
 *
 */
public class CalXiaoxin {
	public static void main(String[] args) {
		cal(598,660.0660,0.6,-1);
//		calKnewA(98,660.0660,0.6, 0.111);
		System.out.println();
	}
	
	/**
	 * 计算
	 * @param x
	 * @param y
	 * @param z
	 * @param figure 位数
	 */
	public static void cal(double x,double y,double z,int figure){
		
		Random random = new Random();
		
		Double amax =  Math.pow(10, figure);
		Double amin = -amax;
		Double nRange = amax-amin;
//        DecimalFormat df = new DecimalFormat("######.#######");
//        String sR = df.format(R);
//        System.out.println(sR);
		
        Double a = random.nextDouble()*nRange;
        a = amax - a;
        
		while(true){
	        a = random.nextDouble()*nRange;
	        a = amax - a;
	        
	        calKnewA(x,y,z,a);
		}
	}
	
	/**
	 * 已知a计算b
	 * @param x
	 * @param y
	 * @param z
	 * @param a
	 */
	public static void calKnewA(double x,double y,double z,double a){
		Random random = new Random();
		
		Double Rmax = 0.001;
		Double Rmin = -0.001;
		Double nRange = Rmax-Rmin;
		Double nRandomDouble = random.nextDouble()*nRange;
		Double R = Rmax - nRandomDouble;
		DecimalFormat df = new DecimalFormat("#####.########");
		
		Double b = -(R-z+a*x)/y;
		System.out.println("R=z-x*a-y*b:");
		System.out.println(df.format(R)+"="+z+"-"+x+"*"+df.format(a)+"-"+y+"*"+df.format(b));
		System.out.println("R="+df.format(R));
//		System.out.println("x="+df.format(x));
//		System.out.println("y="+df.format(y));
//		System.out.println("z="+df.format(z));
		System.out.println("a="+df.format(a));
		System.out.println("b="+df.format(b));
		System.out.println();
	}
}








